import requests
import re
from collections import Counter


def main():
    Registration = []
    for page in range(1, 6):
        url = 'http://match.yuanrenxue.com/logo'
        headers = {
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ko;q=0.6',
            'Referer': 'http://match.yuanrenxue.com/match/3',
        }
        response = requests.post(url, headers=headers)
        sessionid = re.findall('(?<=sessionid=).+?(?=;)', response.headers['Set-Cookie'])[0]
        headers = {
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ko;q=0.6',
            'Cookie': 'sessionid=' + sessionid,
            'Referer': 'http://match.yuanrenxue.com/match/3',
        }
        url = 'http://match.yuanrenxue.com/api/match/3?page=' + str(page)
        response = requests.get(url, headers=headers).json()
        for each in response['data']:
            Registration.append(each['value'])
    print(Counter(Registration))
    print(Counter(Registration).most_common(1)[0][0])
    # {8717: 7, 2838: 1, 7609: 1, 6923: 1, 5325: 1, 4118: 1, 8884: 1, 2680: 1, 3721: 1, 8490: 1, 3148: 1, 6025: 1, 8526: 1, 8529: 1, 6481: 1, 9489: 1, 6599: 1, 5500: 1, 185: 1, 8498: 1, 6102: 1, 9222: 1, 2008: 1, 9827: 1, 8224: 1, 2929: 1, 3762: 1, 567: 1, 672: 1, 9524: 1, 7159: 1, 986: 1, 505: 1, 6535: 1, 9491: 1, 3612: 1, 9095: 1, 7357: 1, 9307: 1, 5650: 1, 2109: 1, 23: 1, 2110: 1, 2792: 1}
    # 最高 8717


if __name__ == '__main__':
    main()
